﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using QuanLyDaiLyVersion2.XuLyLuuTru;

namespace QuanLyDaiLyVersion2.XuLyDuLieu
{
    class NguoiDungDAO
    {
        public static List<NguoiDungDTO> dsNguoiDung()
        {
            string strQuery = "SELECT * FROM NGUOIDUNG";
            DataTable dt = DataAccess.ExecQuery(strQuery);

            List<NguoiDungDTO> lstNguoiDung = new List<NguoiDungDTO>();
            foreach(DataRow dr in dt.Rows)
            {
                NguoiDungDTO nguoiDung = new NguoiDungDTO();
                nguoiDung.MatKhau = dr["MatKhau"].ToString();
                nguoiDung.TenNguoiDung = dr["Ten"].ToString();

                lstNguoiDung.Add(nguoiDung);
            }
            return lstNguoiDung;
        }
        public static bool thayDoiTKvaMK(NguoiDungDTO nd, int indexRow)
        {
            string query = "SELECT * FROM NGUOIDUNG";
            DataTable dt = DataAccess.ExecQuery(query);
            DataRow row = dt.Rows[indexRow];
            row.BeginEdit();
            row[0] = nd.MatKhau;
            row[1] = nd.TenNguoiDung;
            row.EndEdit();
            DataAccess.update(dt, query);
            return true;
            /*
            try
            {
                DataAccess.ExecNonQuery(query);
                return true;
            }
            catch(System.Exception e)
            {
                return false;
            }
             */ 
        }
    }
}
